<template>
    <el-dialog
        title="提示"
        :visible.sync="dialogStatus"
        width="400px"
        :close-on-click-modal="true"
        :before-close="closeDialog"
        top="30vh"
    >
        <div class="dialog-title" slot="title">编辑管理员</div>
        <div class="dialog-body">
            <el-form ref="form" :model="form" label-width="80px">
                <el-form-item label="登录账号" prop="loginName" :rules="[{required:true,message:'请输入登录账号',trigger:'blur'}]" style="margin-bottom:15px;">
                    <el-input type="text" size="small" v-model="form.loginName"></el-input>
                </el-form-item>
                <el-form-item label="密码" prop="password" :rules="[{required:false,message:'请输入密码',trigger:'blur'}]" style="margin-bottom:15px;">
                    <el-input type="password" size="small" v-model="form.password"></el-input>
                </el-form-item>
                <el-form-item label="姓名" prop="fullName" :rules="[{required:true,message:'请输入姓名',trigger:'blur'}]" style="margin-bottom:15px;">
                    <el-input type="text" size="small" v-model="form.fullName"></el-input>
                </el-form-item>
                <el-form-item label="手机号" prop="phone" :rules="[
                    {required:true,message:'请输入手机号',trigger:'blur'},
                    {pattern:/^1[3-9]\d{9}$/, message:'手机号格式错误！',trigger:'blur'}
                ]" style="margin-bottom:15px;">
                    <el-input type="text" size="small" v-model="form.phone"></el-input>
                </el-form-item>
                <el-form-item label="角色" prop="role" :rules="[{required:true,message:'请输入角色',trigger:'blur'}]" style="margin-bottom:15px;">
                    <el-select v-model="form.role" placeholder="请选择" size="small">
                        <el-option v-for="(item, index) in roleList" :key="item.name" :label="item.name" :value="item.name"></el-option>
                    </el-select>
                </el-form-item>
                <el-form-item>
                    <el-button type="primary" size="small" @click="onSubmit('form')">立即提交</el-button>
                </el-form-item>
            </el-form>
        </div>
    </el-dialog>
</template>

<script>
export default {
    data(){
        return {
            dialogStatus:false,
            form:{
                loginName:'',   // 登录账号
                password:'',    // 密码
                fullName:'',    // 姓名
                phone:'',       // 手机号
                role:'',        // 角色
            },
            roleList:[
                {name:'管理员'},
                {name:'测试员'},
                {name:'测试'},
            ],
        }
    },
    mounted() {
    },
    methods:{
        // 提交数据
        onSubmit(form){
            this.$refs[form].validate((valid) => {
                if(valid){
                    this.$http.post('/api/sysuser/update', this.form).then(result => {
                        if(result.code == 200){
                            this.$message.success({
                                message:result.msg,
                                onClose:_ => {
                                    this.$emit('refersh', null);
                                    this.closeDialog();
                                }
                            })
                        }else{
                            this.$message.error(result.msg);
                        }
                    });
                }
            });
        },
        // 显示窗口
        openDialog(e){
            this.form = e;
            this.dialogStatus = true;
        },
        // 关闭回调
        closeDialog(e){
            this.dialogStatus = false;
            this.$refs['form'].resetFields();
        },
    }
}
</script>

<style lang="less" scoped>

</style>
